
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

	class EntryForm extends JPanel{
		private JTextField dateField = new JTextField(); 
		private JLabel dateFieldLabel = new JLabel("Date    ",JLabel.RIGHT);
		private JLabel categoryLabel = new JLabel("Category    ", JLabel.RIGHT);
		private JLabel IncExp = new JLabel ("Transaction Type    ", JLabel.RIGHT);
		private JLabel transactions = new JLabel("Transaction    ", JLabel.RIGHT);
		private JLabel transMethod = new JLabel("Transaction Method    ", JLabel.RIGHT);
		private JLabel userLabel = new JLabel("User   ", JLabel.RIGHT);
		private JLabel amount = new JLabel("Amount :  ", JLabel.RIGHT);
		private ButtonGroup radioGroup = new ButtonGroup();
		
		private JRadioButton income = new JRadioButton("Income");
		private JRadioButton expense = new JRadioButton("Expense");

		private JButton submit = new JButton("SUBMIT");		
		private JButton reset = new JButton("RESET");
		private JButton today = new JButton("TODAY");
		
		private String[] transIncomeList;
		private String[] transExpenseList;
		private String[] transMethodList;
		private String[] userList;
		
		private JComboBox transCategory;
		private JComboBox transMethodCategory;
		private JComboBox user;
		private JTextField transContent = new JTextField();
		private JTextField amountContent = new JTextField();
		
		EntryForm(String[] transIncomeType, String[] transExpenseType, String[] transMethodList, String[] userList){
			this.transIncomeList = transIncomeType;
			this.transExpenseList = transExpenseType;
			this.transMethodList = transMethodList;
			this.userList = userList;
			
			Border blackline = BorderFactory.createLineBorder(Color.black);
			this.setSize(325,300);
			
			dateField.setSize(90,20);
			dateField.setLocation(136,15);
			dateField.setEditable(false);
			dateField.setBackground(Color.WHITE);
			today.setSize(80,20);
			today.setLocation(226,15);
			
			
			
			dateFieldLabel.setSize(135,20);
			dateFieldLabel.setLocation(1,15);
			
			IncExp.setSize(135,20);
			IncExp.setLocation(1,45);
			
			income.setSize(80,20);
			income.setLocation(136,45);
			expense.setSelected(true);
			expense.setSize(80,20);
			expense.setLocation(230,45);
			income.setActionCommand("INCOME");
			expense.setActionCommand("EXPENSE");
			radioGroup.add(income);
			radioGroup.add(expense);
			income.addActionListener(new TransactionTypeListener());
			expense.addActionListener(new TransactionTypeListener());
			
			categoryLabel.setSize(135,20);
			categoryLabel.setLocation(1,75);
			transCategory = new JComboBox(transExpenseList);
			transCategory.setSize(170,20);
			transCategory.setLocation(136,75);
			
		    transactions.setSize(135,20);
		    transactions.setLocation(1,105);
		    transMethodCategory = new JComboBox(transMethodList);
		    transContent.setSize(170,20);
		    transContent.setLocation(136,105);
		    
		    transMethod.setSize(135,20);
		    transMethod.setLocation(1,135);
			transMethodCategory.setSize(170,20);
			transMethodCategory.setLocation(136,135);

		    userLabel.setSize(135,20);
		    userLabel.setLocation(1,195);
		    user = new JComboBox(userList);
		    user.setSize(170,20);
		    user.setLocation(136,195);
		    
		    amount.setSize(135,20);
		    amount.setLocation(1,165);
		    amountContent.setSize(170,20);
		    amountContent.setLocation(136,165);
		    
		    submit.setSize(100,40);
		    submit.setLocation(40,235);
		    
		    reset.setSize(100,40);
		    reset.setLocation(190,235);
		    
		    this.setBorder(blackline);
			this.setLayout(null);
			this.add(dateField);
			this.add(categoryLabel);
			this.add(income);
			this.add(expense);
			this.add(dateFieldLabel);
			this.add(IncExp);
			this.add(transactions);
			this.add(transMethod);
			this.add(amount);
			this.add(transCategory);
			this.add(transContent);
			this.add(transMethodCategory);
			this.add(amountContent);
			this.add(submit);
			this.add(reset);
			this.add(userLabel);
			this.add(user);
			this.add(today);
		
		}
		

		//-----------Declaring Setters and Getters for ComboBox--------------
		//Update Transaction Category Combo box
		public void setTransIncomeList(String[] list){
			this.transIncomeList = list;
			transCategory.removeAllItems();
			for (int i=0; i<transIncomeList.length; i++){
				transCategory.addItem(transIncomeList[i]);
			}
		}
		
		public String[] getTransIncomeList(){
			return this.transIncomeList;
		}
		
		public void setTransExpenseList(String[] list){
			this.transExpenseList = list;
			transCategory.removeAllItems();
			for (int i=0; i<transExpenseList.length; i++){
				transCategory.addItem(transExpenseList[i]);
			}
		}
		
		public String[] getTransExpenseList(){
			return this.transExpenseList;
		}
		
		//Update Transaction Method Category Combo box
		public void setTransactionMethodList(String[] list){
			this.transMethodList = list;
			transMethodCategory.removeAllItems();
			for (int i=0; i<transMethodList.length; i++){
				transMethodCategory.addItem(transMethodList[i]);
			}
		}

		public String[] getTransactionMethodList(){
			return this.transMethodList;
		}
		
		//Update User Combo box
		public void setUserList(String[] list){
			this.userList = list;
			user.removeAllItems();
			for (int i=0; i<userList.length; i++){
				user.addItem(userList[i]);
			}
		}
		
		
		public String[] getUserList(){
			return this.userList;
		}
		

		//-----------Declaring Setters and Getters for textField--------------		
		public void setTransContent(String content){
			transContent.setText(content);
		}
		public String getSubmitButtonText(){
			return submit.getText();
		}
		
		public void setSubmitButtonText(String text){
			submit.setText(text);
		}
		public String getTransContent(){
			return transContent.getText();
		}
		
		public void setDateText(String dateText){
			dateField.setText(dateText);
		}
		
		public String getDateText(){
			return dateField.getText();
		}
		
		public void setAmountText(String amount){
			amountContent.setText(amount);
		}
		
		public String getAmount(){
			return amountContent.getText();
		}
		
		public boolean isIncomeSelected(){
			return income.isSelected();
			
		}
		
		
		//-----------Declaring adding ActionListeners Method--------------
		public void addActionListenerToSubmit(ActionListener al){
			submit.addActionListener(al);
		}
		
		public void addActionListenerToReset(ActionListener al){
			reset.addActionListener(al);
		}
		
		public String getTransCategory(){
			return transCategory.getSelectedItem().toString();
		}
		
		public void addActionListenerToTodayButton(ActionListener al){
			today.addActionListener(al);
		}
		
		public String getUser(){
			return user.getSelectedItem().toString();
		}
		
		public String getTransMethod(){
			return transMethodCategory.getSelectedItem().toString();
		}
		
		public void selectIncome(){
			income.setSelected(true);
			expense.setSelected(false);
		}
		public void selectExpense(){
			income.setSelected(false);
			expense.setSelected(true);
		}
		
		//-----------------Change TransCategory--------------------------
		private class TransactionTypeListener implements ActionListener{
			public void actionPerformed(ActionEvent ev) {
				if (ev.getSource().equals(income)){
					//set income list
					setTransIncomeList(transIncomeList);
				}else if (ev.getSource().equals(expense)){
					//set expense list
					setTransExpenseList(transExpenseList);
				}
			}
			
		}
		
		

	}